﻿CREATE TABLE [fb].[Transaction] (
    [TransactionId]   INT             IDENTITY (1, 1) NOT NULL,
    [Amount]          DECIMAL (18, 2) NOT NULL,
    [Comment]         NVARCHAR (MAX)  NULL,
    [TransactionDate] DATETIME        NOT NULL,
    [Status]          INT             NOT NULL,
    [Version]         INT             NOT NULL,
    [CreatedDate]     DATETIME        NOT NULL,
    [UpdatedDate]     DATETIME        NOT NULL,
    [SrcAccountId]    INT             NOT NULL,
    [DstAccountId]    INT             NOT NULL,
    [ProductId]       INT             NULL,
    CONSTRAINT [PK_fb.Transaction] PRIMARY KEY CLUSTERED ([TransactionId] ASC),
    CONSTRAINT [FK_fb.Transaction_fb.Account_DstAccountId] FOREIGN KEY ([DstAccountId]) REFERENCES [fb].[Account] ([AccountId]),
    CONSTRAINT [FK_fb.Transaction_fb.Account_SrcAccountId] FOREIGN KEY ([SrcAccountId]) REFERENCES [fb].[Account] ([AccountId]),
    CONSTRAINT [FK_fb.Transaction_fb.Product_ProductId] FOREIGN KEY ([ProductId]) REFERENCES [fb].[Product] ([ProductId])
);




GO
CREATE NONCLUSTERED INDEX [IX_SrcAccountId]
    ON [fb].[Transaction]([SrcAccountId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_DstAccountId]
    ON [fb].[Transaction]([DstAccountId] ASC);


GO
CREATE NONCLUSTERED INDEX [IX_ProductId]
    ON [fb].[Transaction]([ProductId] ASC);

